<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <h2>表单输入绑定</h2>
      <!-- <input type="text" :value="textValue" @input="handleChange" /> -->
      <input type="text" v-model="textValue" />
      <span>{{ textValue }}</span>
      <button @click="fn">btn</button>

      <hr />

      <h3>普通文本框</h3>
      <input type="text" v-model="value1" />
      <span>{{ value1 }}</span>

      <hr />

      <h3>多行文本</h3>
      <textarea v-model="value2"></textarea>
      <span>{{ value2 }}</span>

      <hr />

      <h3>复选框</h3>
      <!-- 如果只有一个复选框，默认帮我们绑定一个布尔值 -->
      <input type="checkbox" v-model="value3" />
      <span>{{ value3 }}</span>

      <!-- 如果有多个复选框同时绑定一个变量，这个变量默认是数组类型 -->
      <div>Checked names: {{ value4 }}</div>
      <input type="checkbox" id="jack" value="Jack" v-model="value4" />
      <label for="jack">Jack</label>
      <input type="checkbox" id="john" value="John" v-model="value4" />
      <label for="john">John</label>
      <input type="checkbox" id="mike" value="Mike" v-model="value4" />
      <label for="mike">Mike</label>

      <hr />

      <h3>单选框</h3>
      <div>Picked: {{ picked }}</div>
      <input type="radio" id="one" value="One" v-model="picked" />
      <label for="one">One</label>
      <input type="radio" id="two" value="Two" v-model="picked" />
      <label for="two">Two</label>

      <hr />

      <h3>下拉框</h3>
      <div>Selected: {{ selected }}</div>
      <select v-model="selected">
        <option disabled value="">Please select one</option>
        <option value="a">A</option>
        <option value="b">B</option>
        <option value="c">C</option>
      </select>
    </div>

    <script src="./lib/vue3.js"></script>
    <script>
      Vue.createApp({
        data() {
          return {
            textValue: "hello",
            value1: "11",
            value2: "22",
            value3: true,
            value4: [],
            picked: "",
            selected: "",
          };
        },
        methods: {
          handleChange(e) {
            this.textValue = e.target.value;
          },
          fn() {
            console.log(this.textValue);
          },
        },
      }).mount("#app");
    </script>
  </body>
</html>
